package com.estronger.shopmanage.ui.install;

import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.estronger.shopmanage.R;
import com.estronger.shopmanage.base.BaseActivity;
import com.estronger.shopmanage.base.MyApplication;
import com.estronger.shopmanage.bean.AbnormalType;
import com.estronger.shopmanage.bean.B12Measure;
import com.estronger.shopmanage.bean.B21SendDetail;
import com.estronger.shopmanage.bean.B31BuildDetail;
import com.estronger.shopmanage.bean.B32BuildContent;
import com.estronger.shopmanage.bean.BeanBase;
import com.estronger.shopmanage.bean.BeanImage;
import com.estronger.shopmanage.manager.NetManager;
import com.estronger.shopmanage.ui.order.bean.OrderAttributeBean;
import com.estronger.shopmanage.ui.send.SendRegisterActivity;
import com.estronger.shopmanage.utils.JsonUtil;
import com.estronger.shopmanage.utils.TimeUtils;
import com.estronger.shopmanage.utils.Toast;
import com.estronger.shopmanage.view.AbnormalDeclareView;
import com.estronger.shopmanage.view.AddPhotosView;
import com.estronger.shopmanage.view.AddVideoView;
import com.estronger.shopmanage.view.AppDialog;
import com.estronger.shopmanage.view.YesRecordView;
import com.lidroid.xutils.http.RequestParams;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.soonfor.evaluate.tools.CustomDialog;
import com.soonfor.evaluate.tools.ImageUtils;
import com.soonfor.evaluate.tools.dialog.normal.OnBtnClickL;
import com.soonfor.systemcodes.SystemCodes;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 安装完工登记
 */

public class BuildRegisterActivity extends BaseActivity implements AddPhotosView.EventListener, AbnormalDeclareView.CallBack {

    private Activity mActivity;
    @BindView(R.id.measure_title)
    TextView tv_title;
    @BindView(R.id.result_build_name)
    TextView tv_client;
    @BindView(R.id.result_build_date_real)
    TextView  tv_actual_time;
    @BindView(R.id.bottom_for_build)
    LinearLayout ll_bottom_build;
    @BindView(R.id.bottom_for_send)
    LinearLayout ll_bottom_send;
    //证言录音
    private RelativeLayout rl_yes_record;
    private YesRecordView view_yes_record;
    private String uploadMP3path;//上传录音
    private int recordingLong = 0;//录音的时长

    //安装前中后 照片
    @BindView(R.id.view_build_before)
    AddPhotosView view_build_before;
    @BindView(R.id.view_build_ing)
    AddPhotosView view_build_ing;
    @BindView(R.id.view_build_after)
    AddPhotosView view_build_after;
    /*安装视频*/
    @BindView(R.id.view_install_after_video)
    AddVideoView  view_video;
    @BindView(R.id.result_build_real_time)
    TextView tv_real_time;//实际上门安装时间
    private String dlvid;
    private final int SELECT_FILE = 3;
    @BindView(R.id.build_input_remark)
    EditText et_input_remark;
    private boolean beforeUploadFn = false, buildingUploadFn = false, afterUploadFn = false,videoUploadFn = false;
    private ArrayList<String> beforePaths = new ArrayList<String>();//安装前的图片
    private ArrayList<String> buildingPaths = new ArrayList<String>();//安装中的图片
    private ArrayList<String> afterPaths = new ArrayList<String>();//安装后的图片
    private ArrayList<BeanImage> videoPaths = new ArrayList<>();//安装后的图片

    private RequestParams savaParams;
    private final int CODE_BUILDING_BEFORE = 3000, CODE_BUILDING_ING = 4000, CODE_BUILDING_AFTER = 5000;
    private final int CODE_VIDEO = 6001;
    private final int CODE_DELETE_IMG = 6002;//删除图片
    private final int CODE_DELETE_VIDEO = 6003;//删除视频
    private View rootView;
    private AbnormalDeclareView viewAbnormalDeclare;//异常申报View
    private int pageType = 0;//页面用途 0-安装完工登记 1-仅上传图片和录音，不完工登记

    AddPhotosView operatePhotoView;
    int deletePosition = -1;
    B31BuildDetail sendDetail;//记录详情书

    @Override
    protected void init() {
        mActivity = BuildRegisterActivity.this;
        Intent nIntent = getIntent();
        dlvid = nIntent.getStringExtra("dlvid");
        pageType = nIntent.getIntExtra("pageType", 0);
        // popUtil = new PopManager(this);
        RequestParams params = new RequestParams();
        params.addBodyParameter("sf_action", "istgettaskdetail");
        params.addBodyParameter("usercode", MyApplication.getUserCode());
        params.addBodyParameter("dlvid", dlvid);
        connect(params, NetManager.BUILD4_CONTENT);
    }

    @Override
    protected void initView() {
        rootView = View.inflate(this, R.layout.activity_result_build, null);
        setContentView(rootView);

        ButterKnife.bind(this);
        ll_bottom_build.setVisibility(View.VISIBLE);
        ll_bottom_send.setVisibility(View.GONE);

        viewAbnormalDeclare = (AbnormalDeclareView) findViewById(R.id.viewAbnormalDeclare);
        if (pageType==1) {
            tv_title.setText("安装确认-上传图片和录音");
        }else {
            tv_title.setText("安装完工登记");
        }
        //2023-05-17 LM000238
        initYesRecord();

        tv_real_time.setText("实际安装时间");
        tv_actual_time.setText(TimeUtils.formatTime(System.currentTimeMillis(), ""));

        view_build_before.initView(mActivity, CODE_BUILDING_BEFORE, this);
        view_build_before.initData("安装前的图片", 99);
        view_build_ing.initView(mActivity, CODE_BUILDING_ING, this);
        view_build_ing.initData("安装中的图片", 99);
        view_build_after.initView(mActivity, CODE_BUILDING_AFTER, this);
        view_build_after.initData("安装后的图片", 99);

        view_build_before.setAddMediaListenner(mediaListenner);
        view_build_ing.setAddMediaListenner(mediaListenner);
        view_build_after.setAddMediaListenner(mediaListenner);

        view_video.initView(mActivity,CODE_VIDEO,this);
        view_video.setVideoViewListenner(videoViewListenner);

        view_video.initData("安装视频", 99);

        if(pageType == 1) {
            viewAbnormalDeclare.setVisibility(View.GONE);
        }else {
            viewAbnormalDeclare.setVisibility(View.VISIBLE);
            viewAbnormalDeclare.initAView(this, "是否产生售后投诉单", this, 1);
        }
    }

    /*删除视频监听*/
    AddVideoView.AddVideoViewListenner videoViewListenner = new AddVideoView.AddVideoViewListenner() {
        @Override
        public void onDeleteVideo(AddVideoView view,final LocalMedia media,final int position) {
            CustomDialog.getCanDismissDialog(BuildRegisterActivity.this, "温馨提示", "此视频存在服务器，确定要删除该视频吗？", new OnBtnClickL() {
                @Override
                public void onBtnClick(View view) {
                    deletePosition = position;
                    RequestParams requestParams = new RequestParams();
                    requestParams.addBodyParameter("sf_action","istdelimg");
                    requestParams.addBodyParameter("usercode",MyApplication.getUserCode());
                    requestParams.addBodyParameter("dlvid",dlvid);
                    requestParams.addBodyParameter("dlvimgitemid",getDeleteImageId(media.getPath()));
                    connect(requestParams,CODE_DELETE_VIDEO);
                }
            });
        }
    };

    /*删除图片监听*/
    AddPhotosView.AddMediaListenner mediaListenner = new AddPhotosView.AddMediaListenner() {
        @Override
        public void onDelete(final AddPhotosView pohoview,final LocalMedia media,final int position) {

            CustomDialog.getCanDismissDialog(BuildRegisterActivity.this, "温馨提示", "此图片存在服务器，确定要删除该图片吗？", new OnBtnClickL() {
                @Override
                public void onBtnClick(View view) {
                    deletePosition = position;
                    operatePhotoView = pohoview;
                    RequestParams requestParams = new RequestParams();
                    requestParams.addBodyParameter("sf_action","istdelimg");
                    requestParams.addBodyParameter("usercode",MyApplication.getUserCode());
                    requestParams.addBodyParameter("dlvid",dlvid);
                    requestParams.addBodyParameter("dlvimgitemid",getDeleteImageId(media.getPath()));
                    connect(requestParams,CODE_DELETE_IMG);
                }
            });
        }
    };

    /*获取媒体文件的id*/
    String getDeleteImageId(String path){
        String decodePath = "";
        try {
            decodePath = URLDecoder.decode(path,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String imgId = "";
        for (B31BuildDetail.BuildIMG buildIMG : sendDetail.data.imgitem){
            if (decodePath.endsWith(buildIMG.imgpath)){
                imgId = buildIMG.dlvimgitemid;
                break;
            }
        }
        return imgId;
    }

    //初始化客户证言逻辑块
    private void initYesRecord() {
        et_input_remark.setVisibility(View.VISIBLE);
        if (pageType == 1) {
//            et_input_remark.setVisibility(View.GONE);
            rl_yes_record = (RelativeLayout) findViewById(R.id.rl_yes_record);
            view_yes_record = (YesRecordView) findViewById(R.id.view_yes_record);
            view_yes_record.initView(mActivity, rootView, new YesRecordView.ActionListener() {
                @Override
                public void saveRecord(String recordPath) {
                    File file = new File(recordPath);
                    // if (file.exists())
                    // Log.i("JSON", "local recordPath = " + recordPath);
                    RequestParams p = new RequestParams();
                    p.addBodyParameter("usercode", MyApplication.getUserCode());
                    p.addBodyParameter("dir", "file");
                    p.addBodyParameter("imgFile", file);
                    connect(p, NetManager.FILEUPDATE);
                    view_yes_record.afterSave(recordPath);
                }

                @Override
                public void updateUpTime(int upTime) {
                    recordingLong = upTime;
                }
            });
            rl_yes_record.setVisibility(View.VISIBLE);
        }else {
            et_input_remark.setVisibility(View.VISIBLE);
        }
    }

    // 组建json提交服务器
    private void buildJson() {
        if (beforeUploadFn && buildingUploadFn && afterUploadFn && videoUploadFn) {
            buildIMGJson();
        }
    }
    // 组建json提交服务器
    private void buildIMGJson() {
        try {
            JSONArray jsonArr = new JSONArray();
            for (int i = 0; i < beforePaths.size(); i++) {
                JSONObject jsonObj = new JSONObject();
                jsonObj.put("dlvid", dlvid);
                jsonObj.put("imgpath", beforePaths.get(i));
                jsonObj.put("phaselv", 1);
                jsonArr.put(jsonObj);
            }
            for (int i = 0; i < buildingPaths.size(); i++) {
                JSONObject jsonObj = new JSONObject();
                jsonObj.put("dlvid", dlvid);
                jsonObj.put("imgpath", buildingPaths.get(i));
                jsonObj.put("phaselv", 2);
                jsonArr.put(jsonObj);
            }
            for (int i = 0; i < afterPaths.size(); i++) {
                JSONObject jsonObj = new JSONObject();
                jsonObj.put("dlvid", dlvid);
                jsonObj.put("imgpath", afterPaths.get(i));
                jsonObj.put("phaselv", 3);
                jsonArr.put(jsonObj);
            }
            for (BeanImage beanImage : videoPaths){
                JSONObject jsonObj = new JSONObject();
                jsonObj.put("dlvid", dlvid);
                jsonObj.put("videoimgpath",beanImage.filepath);
                jsonObj.put("imgpath", beanImage.videoimgpath);
                jsonObj.put("filetype","3");
                jsonObj.put("phaselv", 3);
                jsonArr.put(jsonObj);
            }
            savaParams.addBodyParameter("imgitem", jsonArr.toString());
            // Log.i("GAOUJ", "BUILD JSON = " + jsonArr.toString());
            if (pageType == 1) {
                //仅上传图片和录音，不完工登记
                savaParams.addBodyParameter("fifupfinflag", "0");
                //如果是上传图片
                if (!TextUtils.isEmpty(uploadMP3path)) {
                    JSONObject jsonObj = new JSONObject();
                    jsonObj.put("dlvid", dlvid);
                    jsonObj.put("imgpath", uploadMP3path);
                    jsonObj.put("filetype", "2");
                    jsonObj.put("filelength", recordingLong);
                    jsonArr.put(jsonObj);
                }
                savaParams.addBodyParameter("voiceitem", jsonArr.toString());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        connect(savaParams, NetManager.BUILD_RESULT);
    }

    // 时间选择
    public void showPicker(View view) {
        AppDialog.createPicker(this, tv_actual_time).show();
    }

    //获取异常类型
    @Override
    public void getAbnormalType() {
        RequestParams rqTypes = new RequestParams();
        rqTypes.addBodyParameter("sf_action", "getabnormaltype");
        rqTypes.addBodyParameter("usercode", MyApplication.getUserCode());

        showDialog("请求异常类型...", true);
        connect(rqTypes, NetManager.BUILD_ABN_TYPES);
    }
    //打开图库
    @Override
    public void openAlbum(int id) {
        if (isOutOfLimit(id)) return;
        List<LocalMedia> lastMedias = new ArrayList<>();
        if (id == CODE_BUILDING_BEFORE) {
            lastMedias.addAll(view_build_before.getFileList());
        }else if (id == CODE_BUILDING_ING) {
            lastMedias.addAll(view_build_ing.getFileList());
        }else if (id == CODE_BUILDING_AFTER) {
            lastMedias.addAll(view_build_after.getFileList());
        }
        ImageUtils.pictureSelect(mActivity, PictureConfig.MULTIPLE, 99, lastMedias, id + 1);
    }

    //打开相机拍照
    @Override
    public boolean openCamera(int id) {
        // 当达到最高图片数量时直接返回
        return isOutOfLimit(id);
//        if (isOutOfLimit(id))
//            return;
//        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//        startActivityForResult(intent, id + 2);
    }


    @Override
    public void showLoadDialog() {
        showDialog("上传图片中...", false);
    }

    @Override
    public void closeLoadDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

    /**
     * 判断容器里的图片是否达到最高选择数量
     */
    private boolean isOutOfLimit(int code) {
        // 下面开始判断整体容器里的图片是否达到最高选择数量
        if (code == CODE_BUILDING_BEFORE) {
            if (view_build_before.getPhotosCount() >= 99) {
                Toast.show(mActivity, "安装前的图片最多可上传99张", 2000);
                return true;
            }
        } else if (code == CODE_BUILDING_ING) {
            if (view_build_ing.getPhotosCount() >= 99) {
                Toast.show(mActivity, "安装中的最多可上传99张", 2000);
                return true;
            }
        } else if (code == CODE_BUILDING_AFTER) {
            if (view_build_after.getPhotosCount() >= 99) {
                Toast.show(mActivity, "安装后的图片最多可上传99张", 2000);
                return true;
            }
            return false;
        }
        return false;
    }

    //选择文件
    public void select_file(int id) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");// 设置类型，我这里是任意类型，任意后缀的可以这样写。
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent, SELECT_FILE);
    }

    @Override
    protected void onActivityResult(int request, int result, Intent data) {
        super.onActivityResult(request, result, data);
        if (result != Activity.RESULT_OK) {
            return;
        }
        if (request == AbnormalDeclareView.REQUEST_CODE_CHOISE_AB_TYPE) {//选中异常申报类型后
            if (data != null) {
                OrderAttributeBean checkedBean = data.getParcelableExtra(AbnormalDeclareView.BIND_DATA);
                viewAbnormalDeclare.setAbTypeText(checkedBean.getAttId(), checkedBean.getAttName());
            }
        } else {
            //此处判断绝对值似乎有问题，新增判断时，使用的code需增加下面判断大于4的，否则会被上面的方法拦截
            if (Math.abs(request - CODE_BUILDING_BEFORE) < 4) {//安装前
                view_build_before.onActivityResult(request, data);
            }else if (Math.abs(request - CODE_BUILDING_ING) < 4){//安装中
                view_build_ing.onActivityResult(request, data);
            }else if (Math.abs(request - CODE_BUILDING_AFTER) < 4){//安装后
                view_build_after.onActivityResult(request, data);
            }else if(request == CODE_VIDEO + 1 ){
                view_video.onActivityResult(request,data);
            }
        }
    }
    //提及搜
    public void save(View view) {
        String ridate = tv_actual_time.getText().toString().trim();
        String ctsNeed = et_input_remark.getText().toString().trim();
        //安装时间
        if (TextUtils.isEmpty(ridate)) {
            Toast.show(mActivity, "实际安装时间不能为空", 2000);
            return;
        }
        //图片
        if (SystemCodes.getInstance().getDSM_IfFinishCanUpdateAttaOnly()==1) {
            //启用了参数情况下
            if (view_build_before.getPhotosCount() == 0 && view_build_ing.getPhotosCount() == 0 && view_build_after.getPhotosCount() == 0) {
                Toast.show(mActivity, "请至少上传一张图片", 2000);
                return;
            }
        }else {
            //原模式 保持原逻辑
            if (view_build_before.getPhotosCount() == 0 || view_build_ing.getPhotosCount() == 0 || view_build_after.getPhotosCount() == 0) {
                Toast.show(mActivity, "必须上传安装前、中、后的图片", 2000);
                return;
            }
            /*安装完工时*/
            if (pageType == 0) {
                if (SystemCodes.getInstance().getDSM_FinishMustRemark() == 1 && TextUtils.isEmpty(ctsNeed)) {
                    Toast.show(mActivity, "请先输入备注说明", 2000);
                    return;
                }
            }
        }
        if (SystemCodes.getInstance().getDSM_IstFinishMustVideo() == 1 && view_video.getPhotosCount() == 0){
            Toast.show(mActivity, "请至少上传一个视频", 2000);
            return;
        }

        savaParams = new RequestParams();
        savaParams.addBodyParameter("sf_action", "istfinish");
        savaParams.addBodyParameter("usercode", MyApplication.getUserCode());
        savaParams.addBodyParameter("dlvid", dlvid);
        savaParams.addBodyParameter("ridate", ridate);
        savaParams.addBodyParameter("istremark", ctsNeed);

        if (viewAbnormalDeclare != null && viewAbnormalDeclare.resultBean != null) {
            AbnormalDeclareView.ResultBean resultBean = viewAbnormalDeclare.getDatas();
            if(resultBean.getIfGenAdOrder() == 1 && resultBean.getAbnormalDesc().equals("")) {
                Toast.show(mActivity, "投诉诉求不能为空", 2000);
                return;
            }
            savaParams.addBodyParameter("fifgenabnbill", resultBean.getIfGenAdOrder() + "");
            savaParams.addBodyParameter("fabnormaltype", resultBean.getTypeCode());
            savaParams.addBodyParameter("fabnremark", resultBean.getAbnormalDesc());
        }
        initUpload();
        // 上传安装前的的图片
        view_build_before.postPics();
        // 上传安装中的的图片
        view_build_ing.postPics();
        // 上传安装后的的图片
        view_build_after.postPics();
        /*上传视频*/
        view_video.postPics();
    }

    private void initUpload() {
        showDialog("提交数据中...", false);
        if (beforePaths == null) beforePaths = new ArrayList<>();
        else beforePaths.clear();
        beforeUploadFn = false;
        if (buildingPaths == null) buildingPaths = new ArrayList<>();
        else buildingPaths.clear();
        buildingUploadFn = false;
        if (afterPaths == null) afterPaths = new ArrayList<>();
        else afterPaths.clear();
        afterUploadFn = false;
        if (videoPaths == null) videoPaths = new ArrayList<>();
        else videoPaths.clear();
        videoUploadFn = false;
    }

    //上传单张图片
    @Override
    public void uploadPic(RequestParams params, int requestCode) {
        updateIMG(params, requestCode);
    }

    @Override
    public void uploadVideoByParam(RequestParams params, int code) {
        uploadVideo(params, code);
    }

    @Override
    public void afterUploadVideos(boolean isSuccess, ArrayList<BeanImage> urls, int requestCode) {
        videoUploadFn = true;
        videoPaths = urls;
        buildJson();
    }

    //所有图片上传成功
    @Override
    public void afterUploadPics(boolean isSuccess, ArrayList<String> urls, int requestCode) {
        if (isSuccess) {
            if (requestCode == CODE_BUILDING_BEFORE) {
                beforeUploadFn = true;
                beforePaths = urls;
            }else if (requestCode == CODE_BUILDING_ING) {
                buildingUploadFn = true;
                buildingPaths = urls;
            }else if (requestCode == CODE_BUILDING_AFTER) {
                afterUploadFn = true;
                afterPaths = urls;
            }
            buildJson();
        }else {
            closeLoadDialog();
        }
    }

    /**
     * 上传图片成功的回调
     * @param code
     * @param result
     */
    @Override
    protected void onNetIMGSuccess(int code, String result) {
        if (code == CODE_BUILDING_BEFORE) view_build_before.uploadSuccess(code,result);
        else if (code == CODE_BUILDING_ING) view_build_ing.uploadSuccess(code,result);
        else if (code == CODE_BUILDING_AFTER) view_build_after.uploadSuccess(code,result);
        else if (code == CODE_VIDEO) view_video.uploadSuccess(code,result);
    }


    /**
     * 非上传图片的网络请求成功回调
     * @params code 各个接口返回的唯一识别码，用来判断是哪个接口成功返回
     * @params result 网络请求成功返回的数据
     */
    @Override
    protected void onNetSuccess(int code, String result) {
        if (NetManager.BUILD_ABN_TYPES == code) {
            AbnormalType aType = null;
            try {
                aType = gson.fromJson(result, AbnormalType.class);
            } catch (Exception e) {
            }
            if (aType != null) {
                viewAbnormalDeclare.showListDialog(1, aType.data);
            }
        } else {
            if (NetManager.BUILD4_CONTENT == code) {
                super.onNetSuccess(code, result);
                B31BuildDetail bean = gson.fromJson(result,B31BuildDetail.class);
                // 进入activity时获取的同事信息
                if (bean.success) {
                    sendDetail = bean;

                    if (TextUtils.isEmpty(bean.data.buildname)) {
                        tv_client.setText(bean.data.cstname);
                    } else {
                        tv_client.setText(bean.data.buildname + "-"
                                + bean.data.cstname);
                    }
                    List<LocalMedia> preImgArr = new ArrayList<>();
                    List<LocalMedia> ingArr = new ArrayList<>();
                    List<LocalMedia> afterArr = new ArrayList<>();
                    List<LocalMedia> videoImgArr = new ArrayList<>();

                    for (B31BuildDetail.BuildIMG buildIMG : bean.data.imgitem){
                        LocalMedia media = new LocalMedia();
                        String component = "";
                        String videoimgpath = "";
                        try {
                            component = URLEncoder.encode(buildIMG.imgpath, "UTF-8");
                            videoimgpath = URLDecoder.decode(buildIMG.videoimgpath,"UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        String url = NetManager.getDownloadURL() + "?filepath=" + component;
                        media.setPath(url);
                        if (!TextUtils.isEmpty(videoimgpath)){//视频缩略图房子啊压缩图路径中
                            videoimgpath = NetManager.getDownloadURL() + "?filepath=" + videoimgpath;
                            media.setCompressPath(videoimgpath);
                        }else {
                            media.setCompressPath(url);
                        }
                        media.setMimeType(PictureMimeType.ofJPEG());

                        if (buildIMG.phaselv == 1){
                            preImgArr.add(media);
                        }else if (buildIMG.phaselv == 2){
                            ingArr.add(media);
                        }else if (buildIMG.phaselv == 3){
                            if (buildIMG.filetype.equals("3")){
                                media.setCompressPath(url);
                                media.setPath(videoimgpath);
                                videoImgArr.add(media);
                            }else {
                                afterArr.add(media);
                            }
                        }
                    }
                    view_build_before.setImagesList(preImgArr);
                    view_build_ing.setImagesList(ingArr);
                    view_build_after.setImagesList(afterArr);
                    view_video.setVideoList(videoImgArr);
                }
            }else if (NetManager.FILEUPDATE == code) {//上传录音文件
                BeanImage bean = gson.fromJson(result, BeanImage.class);
                if (bean.error == 0) {
                    uploadMP3path = bean.filepath;
                    // Log.i("JSON", "uploadMP3path = " + uploadMP3path);
                    view_yes_record.clear();
                }
            } else if (NetManager.BUILD_RESULT == code) {
                super.onNetSuccess(code, result);
                B12Measure designer = gson.fromJson(result, B12Measure.class);
                // 进入activity时获取的同事信息
                clearUpdateData();
                if (designer.success) {
                    Toast.show(this, "提交成功", 2000);// designer.msg
                    setResult(BuildActivity.REFLESH_DATA);
                    finish();
                } else {
                    Toast.show(this, "提交失败 = " + designer.msg, 2000);
                    Log.i("JSON", "提交失败 = " + designer.msg);
                }closeLoadDialog();
            } else if (CODE_DELETE_IMG == code){//删除图片
                BeanBase beanBase = gson.fromJson(result,BeanBase.class);
                if (beanBase.success){
                    if (operatePhotoView != null){
                        operatePhotoView.removeItem(deletePosition);
                        operatePhotoView = null;
                        deletePosition = -1;
                    }
                }else {
                    Toast.show(mActivity,beanBase.msg,Toast.LENGTH_LONG);
                }
            }else if (CODE_DELETE_VIDEO == code){
                BeanBase beanBase = gson.fromJson(result,BeanBase.class);
                if (beanBase.success){
                    view_video.removeItem(deletePosition);
                    deletePosition = -1;
                }else {
                    Toast.show(mActivity,beanBase.msg,Toast.LENGTH_LONG);
                }
            }
        }
    }
    private void clearUpdateData() {
        savaParams = null;
    }

    /**
     * 请求失败的回调
     * @param code
     * @param msg
     */
    @Override
    protected void onNetErorr(int code, String msg) {
        super.onNetErorr(code, msg);
        if (code == CODE_BUILDING_BEFORE) view_build_before.uploadFail(code, msg);
        else if (code == CODE_BUILDING_ING) view_build_ing.uploadFail(code, msg);
        else if (code == CODE_BUILDING_AFTER) view_build_after.uploadFail(code, msg);
        else if (code == CODE_VIDEO) view_video.uploadFail(code,msg);
        else if (NetManager.BUILD_RESULT == code) {
            clearUpdateData();
            closeLoadDialog();
        }else if (NetManager.FILEUPDATE == code) {
            Log.i("JSON", "error uploadMP3path = " + uploadMP3path);
        }
    }
}
